package com.example.testcontrol;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.animation.LinearInterpolator;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MainActivity extends Activity {
	
	private Context context;
	private Button btn, btn2, btn3;
	private RelativeLayout rel1;
	boolean bTouch = false;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		context = this;
		btn = (Button) findViewById(R.id.btn);
		btn.setVisibility(View.INVISIBLE);
		btn2 = (Button) findViewById(R.id.button2);
		btn3 = (Button) findViewById(R.id.button3);
		rel1 = (RelativeLayout) findViewById(R.id.rel1);
		rel1.setVisibility(View.INVISIBLE);
		
		btn.setOnClickListener(new OnClickListener() 
		{
						
			@Override
			public void onClick(View v) {
//				Intent intent = new Intent(MainActivity.this,dialog.class);
//				startActivity(intent);
				
				final Dialog dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
				dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
				dialog.setContentView(R.layout.custom_dialog);
				dialog.setCancelable(true);
	 
				// set the custom dialog components - text, image and button

				ImageView image = (ImageView) dialog.findViewById(R.id.imageView1);
				image.setImageResource(R.drawable.ic_launcher);
	 
				Button dialogButton = (Button) dialog.findViewById(R.id.button1);
				// if button is clicked, close the custom dialog
				dialogButton.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						dialog.dismiss();
					}
				});
	 
				dialog.show();
		
			}
		});
	}
	@Override
	 public boolean onTouchEvent(MotionEvent e)
	{
		final int action = e.getAction();
		switch (action)
		{
			case MotionEvent.ACTION_DOWN:
				if(bTouch == true)
				{
					btn.setVisibility(View.VISIBLE);
					rel1.setVisibility(View.VISIBLE);
					bTouch = false;
				}
				else
				{
					btn.setVisibility(View.INVISIBLE);
					rel1.setVisibility(View.INVISIBLE);
					bTouch = true;
				}
				break;
			default:
				break;
		}
		return true;
	}
	
//	@Override
//	public boolean onCreateOptionsMenu(Menu menu) {
//		// Inflate the menu; this adds items to the action bar if it is present.
//		getMenuInflater().inflate(R.menu.main, menu);
//		return true;
//	}
	 protected void setOrientation() {
	        int current = getRequestedOrientation();
	        // only switch the orientation if not in portrait
	        if ( current != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ) {
	            setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_NOSENSOR );
	        }
	    }
}
